﻿using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Blog.Core.Model.ViewModels;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;

namespace netCoreStudy.Controllers
{
	/// <summary>
	/// 监控
	/// </summary>
	[ApiController]
	[Route("api/monitor")]
	public class MonitorController : ControllerBase
	{
		private readonly IWebHostEnvironment _env;

		public MonitorController(IWebHostEnvironment env)
		{
			_env = env;
		}

		[HttpGet("server")]
		public IActionResult GetServer()
		{
			return this.SuccessMsg("获取服务器信息成功", new ServerModel()
			{
				EnvironmentName = _env.EnvironmentName,
				OSArchitecture = RuntimeInformation.OSArchitecture.ToString().Trim(),
				ContentRootPath = _env.ContentRootPath,
				WebRootPath = _env.WebRootPath,
				FrameworkDescription = RuntimeInformation.FrameworkDescription,
				MemoryFootprint = (Process.GetCurrentProcess().WorkingSet64 / 1048576).ToString("N2") + " MB",
				WorkingTime = MyCommonMethod.TimeSubTract(DateTime.Now, Process.GetCurrentProcess().StartTime)
			});
		}
	}
}